<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>限流函数</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/lodash@4.17.20/lodash.min.js"></script>
</head>
<body>
    <div id="Application">
        <button @click="click">按钮</button>
    </div>
    <script>
        var throttle = false
        function throttleTool(callback, timeout) {
            if (!throttle) {
                callback()
            } else {
                return
            }
            throttle = true
            setTimeout(() => {
                throttle = false
            }, timeout)
        }
        const App = {
            // data() {
            //     return {
            //         throttle:false // 控制按钮是否可触发的变量
            //     }
            // },
            methods: {
                // click() {
                //     throttleTool(()=>{
                //         console.log(Date())
                //     }, 2000)
                // }
                click: _.debounce(function(){
                    console.log(Date())
                }, 2000)
            }
        }
        Vue.createApp(App).mount("#Application") 
    </script>
</body>
</html>